//
//  WYXCurrCondiDisplay.m
//  ObserverPattern
//
//  Created by ying on 2016/12/14.
//  Copyright © 2016年 ying. All rights reserved.
//

#import "WYXCurrCondiDisplay.h"
#import "WYXHeaders.h"

@interface WYXCurrCondiDisplay ()

@property (nonatomic, strong) NSDictionary *currData;

@end

@implementation WYXCurrCondiDisplay

- (instancetype)initWithWeatherData:(id<WYXSubject>)weatherData{
    self = [super init];
    if (self) {
         // 在构造方法中注册成为weatherData的观察者
        [weatherData registerObserver:self];
    }
    return self;
}
// 接收到有数据更新的通知
- (void)update:(NSDictionary *)data{
    self.currData = data;
    [self display];
}
// 显示当前数据
- (void)display{
    float tem = [[self.currData objectForKey:TEMP] floatValue];
    float hum = [[self.currData objectForKey:HUMI] floatValue];
    float pre = [[self.currData objectForKey:PRES] floatValue];

    NSLog(@"当前最新气况\n 温度：%f\n 湿度：%f\n 气压：%f",tem,hum,pre);
}

@end
